<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>发送通知信息</title>
    <include file="Pub:style" />
    <style>
        .fbox label{
            font-size: 18px;
            padding: 5px 10px;
        }
    </style>
</head>
<body>
    <include file="Pub:nav"/>
    <div class="body">
        <div class="box">
            <div class="rowbox">
                <div class="title">
                    您目前所在的位置 > 公告管理 > 发布消息
                </div>
            </div>
            <div class="rowbox">
                <div class="fbox">
                    <form class="form" id="noticeform">
                        <!-- 通知的主题 -->
                        <div class="form-group row">
                            <label class="col-xs-3 col-md-2 col-sm-offset-2 text-right" for="title">通知主题:</label>
                            <div class="col-xs-8 col-sm-6">
                                <input class="form-control" type="text" name="title" id="title" placeholder="请输入通知的主题" value="">
                            </div>
                        </div>
                        <!-- 通知的对象 -->
                        <div class="form-group row">
                            <label class="col-xs-3 col-md-2 col-sm-offset-2 text-right" for="object">通知的对象:</label>
                            <div class="col-xs-8 col-sm-6">
                                <div style="padding:6px 10px">
                                    <?php if($_GET['uid']){?>
                                        <input type="radio" name="object" id="object1" value="0" >&nbsp;&nbsp;全体用户&nbsp;&nbsp;&nbsp;
                                        <input type="radio" name="object" id="object2" value="1" checked>&nbsp;&nbsp;个人&nbsp;&nbsp;&nbsp;
                                    <?php }else{ ?>
                                        <input type="radio" name="object" id="object1" value="0" checked>&nbsp;&nbsp;全体用户&nbsp;&nbsp;&nbsp;
                                        <input type="radio" name="object" id="object2" value="1" >&nbsp;&nbsp;个人&nbsp;&nbsp;&nbsp;
                                    <?php } ?>
                                </div>
                                <input type="text" name="userid" id="userid" value="<#$Think.get.uid#>" class="form-control" placeholder="通知单个用户id" disabled>
                            </div>
                        </div>
                        <!-- 通知的内容 -->
                        <div class="form-group row">
                            <label class="col-xs-3 col-md-2 col-sm-offset-2 text-right" for="content">通知内容:</label>
                            <div class="col-xs-8 col-sm-6">
                                <!-- <input class="form-control" type="text" name="content" id="content" placeholder="请输入通知的内容" value=""> -->
                                <textarea class="form-control" name="content" id="content" cols="30" rows="10" placeholder="请输入通知的内容"></textarea>
                            </div>
                        </div>
                        <!-- 通知发送的时间 -->
                        <div class="form-group row">
                            <label class="col-xs-3 col-md-2 col-sm-offset-2 text-right" for="sendtime">通知发送的时间:</label>
                            <div class="col-xs-8 col-sm-6">
                                <div class="input-group date form_datetime col-md-6" data-date="1979-09-16T05:25:07Z" data-date-format="dd MM yyyy - HH:ii p" data-link-field="sendtime">
                                    <input class="form-control" size="16" type="text" value="" readonly>
                                    <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-remove"></span>
                                    </span>
                                    <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-th"></span>
                                    </span>
                                </div>
                                <input type="hidden" id="sendtime" name="sendtime" value="" />
                                <br/>
                            </div>
                        </div>
                        <!-- 按钮 -->
                        <div class="form-group col-xs-offset-4 col-xs-4">
                            <button type="button" class="btn btn-primary" onclick="add()">确认保存</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <button type="reset" class="btn btn-info">取&nbsp;&nbsp;&nbsp;消</button>
                        </div>  
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>

<script type="text/javascript">
    // 通知对象选择
    $('input[type=radio][name=object]').change(function(){
        if(this.value =='1'){
            $("#userid").removeAttr('disabled');
            $("#userid").val(<#$Think.get.uid#>);
        }else{
            $("#userid").val("");
            $("#userid").attr('disabled','');
        }
    })
    // 时间选择器
    $('.form_datetime').datetimepicker({
        //language:  'fr',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1
    });
    // 发送信息
    function add(){
        var form_data = $("#noticeform").serializeArray();
        console.log(form_data)
        $.ajax({
            url:"<#:U('Notices/add')#>",
            async:true,
            type:'post',
            data:{data:JSON.stringify(form_data)},
            dataType:'json',
            success:function(res){
                console.log(res.code)
                if(res.code==100){
                    document.location.reload();
                }else if(res.code==200){
                    layer.msg('失败');
                }
            },error:function(res){
                console.log(res)
            }
        })
    }
</script>
</html>